//	--------------------------------------------------------------------
//	Copyright(C) 2006,2007 Zhao Yukun. All rights reserved.
//	This file is a part of the Xeres system.
//	Xeres 2007
//	Contact : xeres.engine@gmail.com
//	$(reservedInfo)
//	$(reservedDeclaration)
//	--------------------------------------------------------------------
///	@file	<ext_style.h>
///	@path	~/src/gui/style/
///	@date	2008/11/16
///	@desc	.

#pragma once

#include "xeres.h"

#include "gui/style/style.h"

namespace xeres {

	/*! 
		\struct	GuiStyle
		\brief	GUI component style.
	*/
	struct GuiStyle
	{
	public:

		/// \ctor
		GuiStyle( void );

		/// \ctor
		GuiStyle( const GuiStyle& rhs );

	public:

		// @data
		ARGB				m_guiBackgroundColor;
		ARGB				m_guiBorderColor;
	};

	/*! 
		\class	CGuiStyle
		\brief
	*/
	class CGuiStyle : public CTextStyle , public MAKE_TYPE( ImageStyle , GuiStyle )
	{
	public:

		/// \ctor
		CGuiStyle( void );

		/// \ctor
		CGuiStyle( const CGuiStyle& rhs );

		/// \dtor
		virtual ~CGuiStyle( void );

		DECL_IOBJECT_CLASS_DYNAMIC( CGuiStyle , CTextStyle );

	public:

		/// \brief	Query style.
		virtual RefWeak<IVar> QueryStyle( const WString& name );

		/// \brief	Set style.
		virtual bool SetStyle( const WString& name , const WString& value );

		/// \brief	Query hover style.
		Ref<CGuiStyle> GetHover( void ) { return m_hover; }

		/// \brief	Query focus style.
		Ref<CGuiStyle> GetFocus( void ) { return m_focus; }

		/// \brief	Query clicked style.
		Ref<CGuiStyle> GetClicked( void ) { return m_clicked; }

		/// \brief	Query disable style.
		Ref<CGuiStyle> GetDisable( void ) { return m_disable; }

		/// \brief	Access hover style (create if none).
		Ref<CGuiStyle> AccessHover( void );

		/// \brief	Access focus style (create if none).
		Ref<CGuiStyle> AccessFocus( void );

		/// \brief	Access clicked style (create if none).
		Ref<CGuiStyle> AccessClicked( void );

		/// \brief	Access disable style (create if none).
		Ref<CGuiStyle> AccessDisable( void );

		/// \brief	Access enable style (redirect to this).
		Ref<CGuiStyle> AccessEnable( void );

	private:

		//@ data
		Ref<CGuiStyle>	m_hover;
		Ref<CGuiStyle>	m_focus;
		Ref<CGuiStyle>	m_clicked;
		Ref<CGuiStyle>	m_disable;
	};

	/*! 
		\class	GuiStyleComp
	*/
	template<
		typename _PrimaryStyle ,
		typename _SecondaryStyle = typename _PrimaryStyle
	>
	class GuiSyleComp
	{
	public:

		/// \ctor
		GuiSyleComp( Ref<_PrimaryStyle> style )
			: m_guiStyle( style )
			, m_activeGuiStyle( m_guiStyle )
		{
		}

		/// \brief	Reset style.
		void ResetStyle( bool enable, bool clicked , bool hover , bool focus )
		{
			if( !enable )
			{
				if( m_guiStyle->GetDisable().IsValid() )
					m_activeGuiStyle = m_guiStyle->GetDisable();
				else
					m_activeGuiStyle = m_guiStyle;
				return;
			}
			// enable-state dispatch
			if( clicked )
			{
				if( m_guiStyle->GetClicked().IsValid() )
				{
					m_activeGuiStyle = m_guiStyle->GetClicked();
					return;
				}
			}
			if( hover )
			{
				if( m_guiStyle->GetHover().IsValid() )
				{
					m_activeGuiStyle = m_guiStyle->GetHover();
					return;
				}
			}
			if( focus )
			{
				if( m_guiStyle->GetFocus().IsValid() )
				{
					m_activeGuiStyle = m_guiStyle->GetFocus();
					return;
				}
			}
			m_activeGuiStyle = m_guiStyle;
		}

	protected:

		//@ data
		Ref<_PrimaryStyle>		m_guiStyle;
		Ref<_SecondaryStyle>	m_activeGuiStyle;
	};

} // namespace xeres
